package org.jackysoft.entity;

import java.util.List;

import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.OneToMany;

import org.apache.struts2.json.annotations.JSON;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.ForeignKey;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;

import com.google.common.collect.Lists;

/**
 * @author Hibernate CodeGenerator 保存运行时的html实际内容
 */
@Entity
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class HTMLDocument extends AbstractAppendinceItem {

	/**
	 * 
	 */
	private static final long serialVersionUID = -2906464719277552661L;

	private List<SimpleHtmlElement> htmlElement = Lists.newArrayList();

	public HTMLDocument() {
	}

	@OneToMany(targetEntity=SimpleHtmlElement.class,orphanRemoval=true)
	@org.hibernate.annotations.Cascade({
		org.hibernate.annotations.CascadeType.ALL,
		org.hibernate.annotations.CascadeType.DELETE,
		org.hibernate.annotations.CascadeType.SAVE_UPDATE
    })
	@LazyCollection(LazyCollectionOption.EXTRA)
	@JSON(serialize=false)
	@JoinTable(name = "htmldocument_element", joinColumns = { @JoinColumn(name = "formentry_id") }, inverseJoinColumns = @JoinColumn(name = "element_id"))
	@ForeignKey(name = "FORM_FK", inverseName = "ELE_FK")
	public List<SimpleHtmlElement> getHtmlElement() {
		return htmlElement;
	}

	/**
	 * @param htmlElements
	 *            要设置的 htmlElements
	 */
	public void setHtmlElement(List<SimpleHtmlElement> htmlElement) {
		this.htmlElement = htmlElement;
	}
	
}
